package com.andyage.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileUtil {
	public static void upFile(InputStream is,String fileName,String filePath){
		FileOutputStream fos=null;
		BufferedOutputStream bos=null;
		BufferedInputStream bis=null;
		File file=new File(filePath);
		if(!file.exists()){
			file.mkdirs();
		}
		File f=new File(filePath+"/"+fileName);
		bis=new BufferedInputStream(is);
		try {
			fos=new FileOutputStream(f);
			bos=new BufferedOutputStream(fos);
			byte[] bt=new byte[4096];
			int len;
			while((len=bis.read(bt))>0){
				bos.write(bt, 0, len);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if(null!=bos){
					bos.close();
					bos=null;
				}
				if(null!=fos){
					fos.close();
					fos=null;
				}
				if(is!=null){
					is.close();
					is=null;
				}
				if(bis!=null){
					bis.close();
					bis=null;
				}
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}
		
	}
}
